$(function() {
  $(".form-comment").on("submit", function(e) {
    e.preventDefault();
    $.ajax({
      headers: {
        ReturnTo: window.location.pathname
      },
      url: "/add-comment",
      method: "post",
      data: {
        essayId: $(".essay-id").val(),
        content: $(".comment-content").val()
      },
      success: function(data) {
        //console.log(data);
        var username=localStorage.getItem("username");
        if (data.status == -1) {
          window.location.href = data.goto;
        } else {
          var html =
            '<li> <div class="comment-header">' +
            "<h6>"+ username+"</h6>" +
            "<span>楼</span>" +
            "</div>" +
            '<div class="comment-body">' +
            "<p>"+$(".comment-content").val()+"</p>" +
            "</div></li>";
           $(".comment-list").prepend($(html));
        }
      }
    });
  });
});
